package com.lancoo.ccas53.controller;

import cn.hutool.core.collection.CollUtil;
import com.lancoo.ccas53.entity.*;
import com.lancoo.ccas53.exception.BizException;
import com.lancoo.ccas53.pojo.dto.*;
import com.lancoo.ccas53.pojo.response.basicPlatform.BaseCourse;
import com.lancoo.ccas53.service.*;
import com.lancoo.ccas53.util.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @Author: mabolin
 * @Date: 2024-06-04-9:50
 * @Description:
 */
@Api(tags = "选课控制器")
@RestController
@RequestMapping("/selectCourse")
public class SelectCourseController {
    @Autowired
    private CssSelectCourseService selectCourseService;
    @Autowired
    private YunBasicService yunBasicService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private CssProhibitStudentService cssProhibitStudentService;
    @Resource
    private TeachingClassService teachingClassService;

    @ApiOperation("获取选课要求")
    @GetMapping("/getCssTask")
    public ResponseObject<CssTaskInfo> getCssTask(@ApiParam(value = "1预选 2正式选课", required = true) @RequestParam Integer type,
                                                  @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getCssTask(type, taskId));
    }

    @ApiOperation("设置选课要求")
    @PostMapping("/setCssTask")
    public ResponseObject<CssTaskInfo> setCssTask(@ApiParam(value = "选课要求参数", required = true) @RequestBody CssTaskInfo param,
                                                  @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.setCssTask(param, taskId));
    }

    @ApiOperation("获取已选选课课程列表")
    @GetMapping("/getSelectCourseList")
    public ResponseObject<List<SelectCourseListDto>> getSelectCourseList(@ApiParam(value = "1预选 2正式选课") @RequestParam(required = false) Integer type,
                                                                         @ApiParam(value = "0全部 1已设置 2未设置") @RequestParam(required = false) Integer dataRange,
                                                                         @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                         @ApiParam(value = "课程类别id") @RequestParam(required = false) String courseTypeId,
                                                                         @ApiParam(value = "课程性质 1必修 2选修") @RequestParam(required = false) Integer courseNature,
                                                                         @ApiParam(value = "课程名模糊查询") @RequestParam(required = false) String keyword,
                                                                         @ApiParam(value = "性别限制 0、男女不限 1、仅男生 2、仅女生") @RequestParam(required = false) Integer sexLimit,
                                                                         @ApiParam(value = "0待选  1已选") @RequestParam(required = false) Integer flag,
                                                                         @ApiParam(value = "任务", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getSelectCourseList(type, dataRange, baseCollegeId, courseTypeId, courseNature, keyword, sexLimit, flag, taskId));
    }

    @ApiOperation("批量设置选课课程")
    @PostMapping("/addSelectCourse")
    public ResponseObject<List<CssSelectCourse>> addSelectCourse(@ApiParam(value = "选课课程", required = true) @RequestBody List<CssSelectCourse> list,
                                                                 @ApiParam(value = "1预选 2正式选课") @RequestParam(required = false) Integer type,
                                                                 @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.addSelectCourse(list, type, taskId));
    }

    @ApiOperation("批量添加课程")
    @PostMapping("/addTempCourse")
    public ResponseObject<Boolean> addTempCourse(@ApiParam(value = "选课课程", required = true) @RequestBody List<CssSelectCourse> list,
                                                 @ApiParam(value = "1预选 2正式选课", required = true) @RequestParam Integer type,
                                                 @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.addTempCourse(list, type, taskId));
    }

    @ApiOperation("批量删除课程")
    @PostMapping("/deleteTempCourse")
    public ResponseObject<Boolean> deleteTempCourse(@ApiParam(value = "id", required = true) @RequestBody List<Long> IdList,
                                                    @ApiParam(value = "1预选 2正式选课", required = true) @RequestParam Integer type,
                                                    @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.deleteTempCourse(IdList, type, taskId));
    }

    @ApiOperation("批量设置课程限制")
    @PostMapping("/setCourseLimit")
    public ResponseObject<String> setCourseLimit(@ApiParam(value = "id列表", required = false) @RequestBody(required = false) List<Integer> idList,
                                                 @ApiParam(value = "性别限制 0、男女不限 1、仅男生 2、仅女生") @RequestParam(required = false) Optional<Integer> sexLimit,
                                                 @ApiParam(value = "最低开班人数") @RequestParam(required = false) Optional<Integer> classNum,
                                                 @ApiParam(value = "操作状态 1未设置 2已设置") @RequestParam(required = false) Optional<Integer> operationStatus,
                                                 @ApiParam(value = "开课状态 0取消开班 1正常开班") @RequestParam(required = false) Optional<Integer> isEnable,
                                                 @ApiParam(value = "说明,撤销原因") @RequestParam(required = false) Optional<String> description,
                                                 @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.setCourseLimit(idList, sexLimit, classNum, operationStatus, isEnable, description, taskId));
    }

    @ApiOperation("获取选课轮次列表")
    @GetMapping("/getRoundList")
    public ResponseObject<List<RoundListDto>> getRoundList(@ApiParam(value = "1预选 2正式选课", required = false) @RequestParam(required = false) Optional<Integer> type,
                                                           @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getRoundList(type, taskId));
    }

    @ApiOperation("添加更新选课轮次信息")
    @PostMapping("/addOrUpdateRound")
    public ResponseObject<Boolean> addOrUpdateRound(@ApiParam(value = "选课课程", required = true) @RequestBody RoundListDto param,
                                                    @ApiParam(value = "authorization", required = true) @RequestHeader("Authorization") String authorization,
                                                    @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) throws UnsupportedEncodingException {
        return ResponseObject.ofSuccess(selectCourseService.addOrUpdateRound(param, authorization, taskId));
    }

    @ApiOperation("删除自选轮次课程")
    @PostMapping("/deleteRoundCourseToSelf")
    public ResponseObject<Boolean> deleteRoundCourseToSelf(@ApiParam(value = "轮次Id") @RequestParam(required = false) Integer roundId,
                                                           @ApiParam(value = "课程Id") @RequestBody(required = false) List<Integer> courseIds,
                                                           @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.deleteRoundCourseToSelf(roundId, courseIds, taskId));
    }

    @ApiOperation("删除选课轮次")
    @DeleteMapping("/removeRound")
    public ResponseObject<Boolean> removeRound(@ApiParam(value = "选课课程", required = true) @RequestParam Integer id,
                                               @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.removeRound(id, taskId));
    }

    @ApiOperation("获取禁选学生列表")
    @GetMapping("/prohibit/getStudentList")
    public ResponseObject<ResultDto<ProhibitStudentDto>> getStudentList(@ApiParam(value = "1预选 2正式选课") @RequestParam(required = false) Integer type,
                                                                        @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                        @ApiParam(value = "年级id") @RequestParam(required = false) String gradeId,
                                                                        @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                                        @ApiParam(value = "名称、学号模糊查询") @RequestParam(required = false) String keyword,
                                                                        @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                        @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                        @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(cssProhibitStudentService.getStudentList(type, baseCollegeId, gradeId, classId, keyword, pageSize, currentPage, taskId));
    }

    @ApiOperation("批量添加禁选学生")
    @PostMapping("/prohibit/addStudent")
    public ResponseObject<Boolean> addStudent(@ApiParam(value = "选课课程", required = true) @RequestBody List<CssProhibitStudent> param,
                                              @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        boolean flag = cssProhibitStudentService.saveBatch(param);
        return ResponseObject.ofSuccess(flag);
    }

    @ApiOperation("批量删除禁选学生")
    @PostMapping(value = "/prohibit/removeStudent")
    public ResponseObject<Boolean> removeStudent(@ApiParam(value = "学生id", required = true) @RequestBody List<Integer> idList,
                                                 @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        cssProhibitStudentService.removeBatchByIds(idList);
        return ResponseObject.ofSuccess(true);
    }

    @ApiOperation("查看预选课选课日志")
    @GetMapping("/getPreLogs")
    public ResponseObject<ResultDto<PreLogsDto>> getPreLogs(@ApiParam(value = "对应年级id") @RequestParam(required = false) Long roundId,
                                                            @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                            @ApiParam(value = "对应年级id") @RequestParam(required = false) String gradeId,
                                                            @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                            @ApiParam(value = "课程id") @RequestParam(required = false) Long courseId,
                                                            @ApiParam(value = "开始时间") @RequestParam(required = false) String startDateTime,
                                                            @ApiParam(value = "结束时间") @RequestParam(required = false) String endDateTime,
                                                            @ApiParam(value = "学号姓名模糊查询") @RequestParam(required = false) String keyword,
                                                            @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                            @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                            @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getPreLogs(roundId, baseCollegeId, gradeId, classId, courseId, startDateTime, endDateTime, keyword, pageSize, currentPage, taskId));
    }

    @ApiOperation("确定预选课结果列表")
    @GetMapping("/getPreResultList")
    public ResponseObject<ResultDto<PreResultDto>> getPreResultList(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                    @ApiParam(value = "课程类别id") @RequestParam(required = false) String courseTypeId,
                                                                    @ApiParam(value = "课程性质 1必修 2选修") @RequestParam(required = false) Optional<Integer> courseNature,
                                                                    @ApiParam(value = "课程名模糊查询") @RequestParam(required = false) String keyword,
                                                                    @ApiParam(value = "开课状态 0取消开班 1正常开班") @RequestParam(required = false) Optional<Integer> isEnable,
                                                                    @ApiParam(value = "是否达到开班要求 0 否 1、是") @RequestParam(required = false) Optional<Integer> isAchieveOpen,
                                                                    @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                    @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                    @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getPreResultList(baseCollegeId, courseTypeId, courseNature, keyword, isEnable, isAchieveOpen, pageSize, currentPage, taskId));
    }

    @ApiOperation("统计选课")
    @GetMapping("/publishStatistics")
    public ResponseObject<Map<String, Object>> publishStatistics(@ApiParam(value = "1预选 2正式选课", required = false) @RequestParam(required = false) Integer type,
                                                                 @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.publishStatistics(type, taskId));
    }

    @ApiOperation("获取选课教学班列表")
    @GetMapping("/getTeachingClassList")
    public ResponseObject<ResultDto<TeachingClassDto>> getTeachingClassList(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                            @ApiParam(value = "课程类别id") @RequestParam(required = false) String courseTypeId,
                                                                            @ApiParam(value = "课程性质 1必修 2选修") @RequestParam(required = false) Integer courseNature,
                                                                            @ApiParam(value = "课程id") @RequestParam(required = false) Integer courseId,
                                                                            @ApiParam(value = "教学班名模糊查询") @RequestParam(required = false) String keyword,
                                                                            @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                            @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                            @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getTeachingClassList(baseCollegeId, courseTypeId, courseNature, courseId, keyword, pageSize, currentPage, taskId));
    }

    @ApiOperation("获取选课学生列表")
    @GetMapping("/getStudentList")
    public ResponseObject<ResultDto<StudentDto>> getStudentList(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                @ApiParam(value = "年级id") @RequestParam(required = false) String gradeId,
                                                                @ApiParam(value = "班级id") @RequestParam(required = false) Optional<Integer> classId,
                                                                @ApiParam(value = "是否选课 1、是 2、否") @RequestParam(required = false) Optional<Integer> isSelect,
                                                                @ApiParam(value = "学生名模糊查询") @RequestParam(required = false) String keyword,
                                                                @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getStudentList(baseCollegeId, gradeId, classId, isSelect, keyword, pageSize, currentPage, taskId));
    }

    @ApiOperation("获取选课学生范围")
    @GetMapping("/getStudentRangeList")
    public ResponseObject<List<StudentRangeDto>> getStudentRangeList(@ApiParam(value = "0按院系 1按年级", required = false) @RequestParam(required = false) Integer flag,
                                                                     @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getStudentRangeList(flag, taskId));
    }

    @ApiOperation("生成选课课程范围")
    @PostMapping("/getClassRangeList")
    public ResponseObject<List<CourseRangeDto>> getClassRangeList(@ApiParam(value = "开课单位id") @RequestParam(required = false) String baseCollegeId,
                                                                  @ApiParam(value = "课程类别") @RequestParam(required = false) String courseTypeId,
                                                                  @ApiParam(value = "课程性质") @RequestParam(required = false) String courseNature,
                                                                  @ApiParam(value = "课程名称模糊搜索") @RequestParam(required = false) String keyword,
                                                                  @ApiParam(value = "选课学生范围") @RequestBody(required = false) List<CssStudentRange> rangeList,
                                                                  @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getClassRangeList(baseCollegeId, courseTypeId, courseNature, keyword, rangeList, taskId));
    }

    @ApiOperation("取消预选课开课状态")
    @PostMapping("/setCourseStatus")
    public ResponseObject<Boolean> setCourseStatus(@ApiParam(value = "课程Id", required = false) @RequestBody(required = false) List<Integer> idList,
                                                   @ApiParam(value = "状态 1已开启  2停开", required = true) @RequestParam Integer isEnable,
                                                   @ApiParam(value = "撤销原因", required = false) @RequestParam(required = false) String reason,
                                                   @ApiParam(value = "提醒方式 0系统内提示 1微信服务号提醒 3全选 4不提醒", required = false) @RequestParam(required = false) Integer remindWay,
                                                   @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.setCourseStatus(idList, isEnable, reason, remindWay, taskId));
    }

    @ApiOperation("确认发布预选课结果")
    @PostMapping("/confirmPreResult")
    public ResponseObject<Boolean> confirmPreResult(@ApiParam(value = "基础平台学院id", required = true) @RequestBody List<String> baseCollegeIdList,
                                                    @ApiParam(value = "预选课提交人id", required = true) @RequestParam String userId,
                                                    @ApiParam(value = "预选课提交人姓名", required = true) @RequestParam String userName,
                                                    @ApiParam(value = "1预选 2正式选课", required = true) @RequestParam Integer type,
                                                    @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.confirmPreResult(baseCollegeIdList, userId, userName, type, taskId));
    }

    @ApiOperation("按专业查询预选课程")
    @GetMapping("/getCourseByMajor")
    public ResponseObject<ResultDto<MajorGrade>> getCourseByMajor(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                  @ApiParam(value = "所属年级") @RequestParam(required = false) String gradeId,
                                                                  @ApiParam(value = "专业") @RequestParam(required = false) String baseMajorId,
                                                                  @ApiParam(value = "模糊查询") @RequestParam(required = false) String keyword,
                                                                  @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                  @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                  @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getCourseByMajor(baseCollegeId, gradeId, baseMajorId, keyword, pageSize, currentPage, taskId));
    }

    @ApiOperation("复制选课轮次")
    @GetMapping("/copyRound")
    public ResponseObject<Boolean> copyRound(@ApiParam(value = "基础平台学院id", required = true) @RequestParam Integer id,
                                             @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.copyRound(id, taskId));
    }

    @ApiOperation("批量设置选课上限")
    @PostMapping("/setCourseByMajor")
    public ResponseObject<Boolean> setCourseByMajor(@ApiParam(value = "主键id", required = true) @RequestBody List<Integer> idList,
                                                    @ApiParam(value = "预选学分上限") @RequestParam(required = false) Double preCreditLimit,
                                                    @ApiParam(value = "预选课程数上限") @RequestParam(required = false) Integer preCourseLimit,
                                                    @ApiParam(value = "学分上限") @RequestParam(required = false) Double creditLimit,
                                                    @ApiParam(value = "课程数上限") @RequestParam(required = false) Integer courseLimit,
                                                    @ApiParam(value = "1按专业 2按学生", required = true) @RequestParam Integer flag,
                                                    @ApiParam(value = "选课范围 1本专业年级 2本专业跨年级 3本院系跨年级 4全部专业年") @RequestParam(required = false) Integer selectionScope,
                                                    @ApiParam(value = "选课范围（预选）") @RequestParam(required = false) Integer selectionScopePre,
                                                    @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.setCourseByMajor(idList, preCreditLimit, preCourseLimit, creditLimit, courseLimit, flag, selectionScope, taskId, selectionScopePre));
    }


    @ApiOperation("根据学生获取选课教学班列表")
    @GetMapping("/getTeachingClassListByStudent")
    public ResponseObject<ResultDto<TeachingClassDto>> getTeachingClassListByStudent(@ApiParam(value = "学生id") @RequestParam(required = false) Integer studentId,
                                                                                     @ApiParam(value = "页容", required = false) @RequestParam Integer pageSize,
                                                                                     @ApiParam(value = "页码", required = false) @RequestParam Integer currentPage,
                                                                                     @ApiParam(value = "任务流程id") @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getTeachingClassListByStudent(studentId, pageSize, currentPage, taskId));
    }

    @ApiOperation("查看在线选课选课日志")
    @GetMapping("/getCssLogs")
    public ResponseObject<ResultDto<CssLogsDto>> getCssLogs(@ApiParam(value = "轮次id") @RequestParam(required = false) Long roundId,
                                                            @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                            @ApiParam(value = "对应年级id") @RequestParam(required = false) String gradeId,
                                                            @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                            @ApiParam(value = "课程id") @RequestParam(required = false) Optional<Integer> courseId,
                                                            @ApiParam(value = "开始时间") @RequestParam(required = false) String startDateTime,
                                                            @ApiParam(value = "结束时间") @RequestParam(required = false) String endDateTime,
                                                            @ApiParam(value = "学号姓名模糊查询") @RequestParam(required = false) String keyword,
                                                            @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                            @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                            @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getCssLogs(roundId, baseCollegeId, gradeId, classId, courseId, startDateTime, endDateTime, keyword, pageSize, currentPage, taskId));
    }

    @ApiOperation("获取学生列表")
    @GetMapping("/getStudentInfoList")
    public ResponseObject<ResultDto<StudentInfoDto>> getStudentInfoList(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                        @ApiParam(value = "对应年级id") @RequestParam(required = false) String gradeId,
                                                                        @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                                        @ApiParam(value = "学号姓名模糊查询") @RequestParam(required = false) String keyword,
                                                                        @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                        @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                        @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getStudentInfoList(baseCollegeId, gradeId, classId, keyword, pageSize, currentPage, taskId));

    }

    @ApiOperation("确认选课结果-获取教学班")
    @GetMapping("/getStudentRetakeClass")
    public ResponseObject<ResultDto<TeachingClass>> getStudentRetakeClass(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                          @ApiParam(value = "课程id") @RequestParam(required = false) Long courseId,
                                                                          @ApiParam(value = "0正选 1重修") @RequestParam(required = false) Integer flag,
                                                                          @ApiParam(value = "学号姓名模糊查询") @RequestParam(required = false) String keyword,
                                                                          @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                          @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                          @ApiParam(value = "轮次", required = false) @RequestParam Integer roundId,
                                                                          @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getStudentRetakeClass(baseCollegeId, courseId, keyword, pageSize, currentPage, taskId, flag, roundId));

    }

    @ApiOperation("通过学生id获取学生信息")
    @PostMapping("/getStudentByIds")
    public ResponseObject<List<Student>> getStudentByIds(@ApiParam(value = "页码", required = false) @RequestBody List<Long> studentIds,
                                                         @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {

        if (CollUtil.isNotEmpty(studentIds)) {
            List<Student> studentList = studentService.lambdaQuery().eq(Student::getTaskId, taskId).in(Student::getStudentId, studentIds).list();
            return ResponseObject.ofSuccess(studentList);
        } else {
            throw new BizException("学生id不能为空");
        }
    }

    @ApiOperation("添加重修教学班")
    @PostMapping("/addStudentRetakeTeachingClass")
    public ResponseObject<String> addStudentRetakeTeachingClass(@ApiParam(value = "TeachingClass对象", required = true) @RequestBody List<AddTeachingClassDto> list,
                                                                @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                @ApiParam(value = "院系id", required = true) @RequestParam String baseCollegeId,
                                                                @ApiParam(value = "院系名称", required = true) @RequestParam String collegeName,
                                                                @ApiParam(value = "年级id", required = false) @RequestParam(required = false) String gradeId,
                                                                @ApiParam(value = "年级名称", required = false) @RequestParam(required = false) String gradeName,
                                                                @ApiParam(value = "校区id", required = true) @RequestParam Integer campusId,
                                                                @ApiParam(value = "校区名称", required = true) @RequestParam String campusName) {
        return ResponseObject.ofSuccess(selectCourseService.addStudentRetakeTeachingClass(list, taskId, baseCollegeId, collegeName, gradeId, gradeName, campusId, campusName));
    }

    @ApiOperation("确认选课结果获取学生列表")
    @GetMapping("/getStudentSelectList")
    public ResponseObject<ResultDto<StudentSelectInfoDto>> getStudentSelectList(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                                @ApiParam(value = "对应年级id") @RequestParam(required = false) String gradeId,
                                                                                @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                                                @ApiParam(value = "学号姓名模糊查询") @RequestParam(required = false) String keyword,
                                                                                @ApiParam(value = "0正选 1重修 2自学") @RequestParam(required = false) Integer flag,
                                                                                @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                                @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                                @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                                @ApiParam(value = "1：仅看存在未选课程的学生") @RequestParam(required = false) Integer needToSelect,
                                                                                @ApiParam(value = "轮次id") @RequestParam(required = false) Integer roundId) {
        return ResponseObject.ofSuccess(selectCourseService.getStudentSelectList(baseCollegeId, gradeId, classId, keyword, pageSize, currentPage, taskId, needToSelect, flag, roundId));
    }


    @ApiOperation("通过学生获取已选教学班")
    @GetMapping("/accessSelectedStudents")
    public ResponseObject<AccessSelectedStudentDto> accessSelectedStudents(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) Long studentId,
                                                                           @ApiParam(value = "0正选 1 重修 2自选") @RequestParam(required = false) Integer flag,
                                                                           @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                           @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                           @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                           @ApiParam(value = "轮次id") @RequestParam(required = false) Integer roundId) {
        return ResponseObject.ofSuccess(selectCourseService.accessSelectedStudents(studentId, pageSize, currentPage, taskId, flag, roundId));
    }


    @ApiOperation("取消开班")
    @GetMapping("/cancelClasses")
    public ResponseObject<String> cancelClasses(@ApiParam(value = "教学班id", required = false) @RequestParam(required = false) Long teachingClassId,
                                                @ApiParam(value = "authorization", required = true) @RequestHeader("Authorization") String authorization,
                                                @ApiParam(value = "Userid", required = true) @RequestHeader("Userid") String userId,
                                                @ApiParam(value = "Username", required = true) @RequestHeader("Username") String userName,
                                                @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.cancelClasses(teachingClassId, authorization, userId, userName, taskId));
    }

    @ApiOperation("获取自学教学班")
    @GetMapping("/getSelfTeachingClassList")
    public ResponseObject<List<TeachingClass>> getSelfTeachingClassList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                        @ApiParam(value = "唯一标识", required = true) @RequestParam String uuid) {
        List<TeachingClass> teachingClassList = teachingClassService.lambdaQuery().eq(TeachingClass::getTaskId, taskId).eq(TeachingClass::getStudentCampus, uuid).list();
        return ResponseObject.ofSuccess(teachingClassList);
    }

    @ApiOperation("获取选课轮次列表-自学")
    @GetMapping("/getRoundListSelf")
    public ResponseObject<List<RoundListDto>> getRoundListSelf(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getRoundListSelf(taskId));
    }

    @ApiOperation("获取课程-自学")
    @GetMapping("/getCourseListSelf")
    public ResponseObject<List<BaseCourse>> getCourseListSelf(@ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
                                                              @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getBaseCourse(schoolId, taskId));
    }

    @ApiOperation("获取选课教学班列表-自学")
    @GetMapping("/getTeachingClassListSelf")
    public ResponseObject<ResultDto<TeachingClassDto>> getTeachingClassListSelf(@ApiParam(value = "课程id", required = true) @RequestParam(required = true) Integer courseId,
                                                                                @ApiParam(value = "页容", required = false) @RequestParam(required = false) Integer pageSize,
                                                                                @ApiParam(value = "页码", required = false) @RequestParam(required = false) Integer currentPage,
                                                                                @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getTeachingClassListSelf(pageSize, currentPage, taskId, courseId));
    }

    @ApiOperation("清空教学班-自学")
    @PostMapping("/clearTeachingClassSelf")
    public ResponseObject<Boolean> clearTeachingClassSelf(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                          @ApiParam(value = "教学班ids", required = true) @RequestBody List<Long> teachingClassIds) {
        return ResponseObject.ofSuccess(selectCourseService.clearTeachingClassSelf(teachingClassIds, taskId));
    }

    @ApiOperation("生成教学班-自学")
    @GetMapping("/setTeachingClassSelf")
    public ResponseObject<TeachingClassSelfDto> setTeachingClassSelf(@ApiParam(value = "课程id", required = true) @RequestParam Integer courseId,
                                                                     @ApiParam(value = "班级数量", required = false) @RequestParam(required = false) Integer sum,
                                                                     @ApiParam(value = "班级容量", required = false) @RequestParam(required = false) Integer capacity,
                                                                     @ApiParam(value = "课程名称", required = true) @RequestParam String courseName,
                                                                     @ApiParam(value = "1 按容量  2 按数量", required = true) @RequestParam Integer type,
                                                                     @ApiParam(value = "学生总数", required = true) @RequestParam Integer total,
                                                                     @ApiParam(value = "课程id") @RequestParam(required = false) Long roundId,
                                                                     @ApiParam(value = "教学班uuid") @RequestParam(required = false) String uuidForOption,
                                                                     @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.setTeachingClassSelf(courseId, courseName, total, roundId, uuidForOption, type, sum, capacity, taskId));
    }

    @ApiOperation("获取选课课程范围-自学")
    @GetMapping("/getCourseSelectionSelf")
    public ResponseObject<CourseSelectionDto> getCourseSelectionSelf(@ApiParam(value = "轮次id", required = false) @RequestParam(required = false) Integer roundId,
                                                                     @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getCourseSelectionSelf(roundId, taskId));
    }


    @ApiOperation("确认选课结果-添加教学班-获取学生")
    @GetMapping("/getStudentListConfirmSelectionResults")
    public ResponseObject<List<Student>> getStudentListConfirmSelectionResults(@ApiParam(value = "1 重修 2 正选") @RequestParam(required = false) Integer flag,
                                                                               @ApiParam(value = "课程id") @RequestParam(required = false) Long courseId,
                                                                               @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(selectCourseService.getStudentListConfirmSelectionResults(taskId, courseId, flag));
    }


    @ApiOperation("选课前判断冲突")
    @GetMapping("/selectConflictCheck")
    public ResponseObject<Boolean> selectConflictCheck(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                          @ApiParam(value = "学生id", required = true) @RequestParam Long studentId,
                                          @ApiParam(value = "教学班id", required = true) @RequestParam Long teachingClassId,
                                          @ApiParam(value = "已选教学班id", required = true) @RequestParam(required = false) String ids) {
        return ResponseObject.ofSuccess(selectCourseService.selectConflictCheck(taskId,studentId,teachingClassId,ids));
    }

    @ApiOperation("获取学生课表")
    @GetMapping(value = "/getStudentSchedule")
    public ResponseObject<List<ScheduleRedisDto>> getStudentSchedule(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                        @ApiParam(value = "学生id", required = true) @RequestParam Long studentId) {
        return ResponseObject.ofSuccess(selectCourseService.getStudentSchedule(taskId, studentId));
    }


}
